package com.magiccompass.alipay.barcode.security.controller;

import java.security.Principal;

import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class VisitAccessDeniedController {
	static Logger logger = LogManager.getLogger(VisitAccessDeniedController.class.getName());
	@RequestMapping(value = "/403", method = RequestMethod.GET)
	public ModelAndView accesssDenied(Principal user,HttpServletRequest request) {
		ModelAndView model = new ModelAndView();		
		String userName = "";
		if (user != null) {
			userName = user.getName() ;
			model.addObject("msg", "Hi " + userName + ", you do not have permission to access this page!");
		} else {
			model.addObject("msg", "You do not have permission to access this page!");
		}
		logger.info("-=-=-=Access Denied, from:"+request.getRemoteAddr()+", user:"+userName);
		model.setViewName("common/403ErrorPage");
		return model;
	}

}
